package com.wnhz.work.yz.fragment.shoppingdetails;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.wnhz.work.yz.BaseActivity;
import com.wnhz.work.yz.R;
import com.wnhz.work.yz.base.BaseFragment;
import com.wnhz.work.yz.bean.Fragment1Bean;

/**
 * Created by d on 2016/12/13.
 */

public class Fragment2 extends BaseFragment {
    private View view;
    private BaseActivity activity;
    private WebView webview;

    private Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            switch (msg.what) {
                case 1:
                    activity.closeDialog();
                    break;

                default:
                    break;
            }
        }

    };


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_shop_details2, null);
        activity = (BaseActivity) getActivity();
        initView();
        return view;
    }

    private void initView() {
        webview = (WebView) view.findViewById(R.id.webview);
    }

    public void settext(Fragment1Bean bean){
        WebSettings settings = webview.getSettings();
        settings.setJavaScriptEnabled(true);
        settings.setUseWideViewPort(false);
        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setLoadWithOverviewMode(true); // 缩放至屏幕的大小

        activity.showDialog();
        if (webview != null) {
            webview.setWebViewClient(new WebViewClient() {
                @Override
                public void onPageFinished(WebView view, String url) {
                    handler.sendEmptyMessage(1);
                    super.onPageFinished(view, url);
                }
            });
//            webview.getSettings().setJavaScriptEnabled(true);
            webview.loadUrl(bean.getParam());
        }
    }


}
